import 'package:flutter/material.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBNavigator.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBMineModule/YBQiYePersonPage/YBNumberManagerProvider/YBQuanCengHomeInputEventBus.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBBaseMineNetWork/YBBaseMineNetWork.dart';

class YBQuanCengHomeInputPage extends StatefulWidget {

  final String titleHeader;
  final String contentStr;
  final String code;

  const YBQuanCengHomeInputPage({Key key, this.titleHeader, this.contentStr, this.code}) : super(key: key);

  @override
  _YBQuanCengHomeInputPageState createState() => _YBQuanCengHomeInputPageState(titleHeader: titleHeader,contentStr: contentStr,code: code);
}

class _YBQuanCengHomeInputPageState extends State<YBQuanCengHomeInputPage> {

  final String titleHeader;
  final String contentStr;
  final String code;

  _YBQuanCengHomeInputPageState({this.titleHeader, this.contentStr, this.code});

  TextEditingController _editingController = TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _editingController.text = contentStr;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(
          title: Text(titleHeader,style: YBTextStyle.TextStyle30313320Medium,),
          elevation: 0,
          actions: [
            Container(
              child: InkWell(
                child: Container(
                  alignment: Alignment.center,
                  child: Padding(
                    padding:EdgeInsets.only(right: YBTextStyle.adapterSize10),
                    child: Text(
                      YBChineseText.mineCompleteTitle,
                      style: YBTextStyle.TextStyle30313312,
                    ),
                  ),
                ),
                onTap: () async {
                  _editingQuanCengHome(_editingController.text);
                },
              ),
            ),
          ],
        ),
        body: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                height: YBTextStyle.adapterSize10,
              ),
              Container(
                height: YBTextStyle.adapterSize45,
                color: YBColor.white,
                child: Padding(
                  padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                  child: TextField(
                    decoration: InputDecoration(
                      hintText: '${YBChineseText.mineQingInputTitle}$titleHeader',
                      border: InputBorder.none,
                    ),
                    controller: _editingController,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  void _editingQuanCengHome(String editText){
    Map<String,dynamic> quanCengMap = Map<String,dynamic>();
    quanCengMap['sysCode'] = 'xg_youbang';
    if (titleHeader.contains('品牌名称') == true){
      quanCengMap['brandName'] = editText;
    }
    if (titleHeader.contains('联系人') == true){
      quanCengMap['linkName'] = editText;
    }
    if (titleHeader.contains('联系电话') == true){
      quanCengMap['linkPhone'] = editText;
    }
    if (titleHeader.contains('城市') == true){
      quanCengMap['cityName'] = editText;
    }
    if (titleHeader.contains('地址') == true){
      quanCengMap['address'] = editText;
    }
    if (titleHeader.contains('网址') == true){
      quanCengMap['customerUrl'] = editText;
    }
    if (titleHeader.contains('邮箱') == true){
      quanCengMap['email'] = editText;
    }
    if (titleHeader.contains('简介') == true){
      quanCengMap['detail'] = editText;
    }
    YBMineNetWork.mineQuanCengHomeEditingData(quanCengMap,success:(data){
      print('--$data-');
      bool dataBool = data['body'];
      if (dataBool == true){
        quanCengHomeInputEventBus.fire(YBQuanCengHomeInputEventBus(title: titleHeader,content:editText));
        YBNavigatorUtil.goDefaultBack(context);
      }
    },fail: (error){
      print('---$error');
    });
  }

}
